package org.cip.esymons.eventos.bc;

import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import org.cip.esymons.eventos.be.DetalleConcepto;

/**
 *
 * @author Lizardo
 */
public class DetalleConceptoDelegate {

    DetalleConceptoFacadeLocal local;

    public DetalleConceptoDelegate() {
        local = lookupDetalleConceptoFacade();
    }

    public List<DetalleConcepto> listarxTipoConcepto(int i) throws Exception {
        return local.listarxConcepto(i);
    }

    public DetalleConcepto buscarDetalleConcepto(Integer dcoCodigo) {
        try {
            return local.find(dcoCodigo);
        } catch (Exception e) {
            return new DetalleConcepto();
        }
    }

    private DetalleConceptoFacadeLocal lookupDetalleConceptoFacade() {
        try {
            Context c = new InitialContext();
            return (DetalleConceptoFacadeLocal) c.lookup("java:comp/env/DetalleConceptoFacade");
        } catch (NamingException ne) {
            Logger.getLogger(getClass().getName()).log(Level.SEVERE, "exception caught", ne);
            throw new RuntimeException(ne);
        }
    }

    public List<DetalleConcepto> detalleporConcepto(int idTipoConcepto) {
        try {
            return local.listarxConcepto(idTipoConcepto);
        } catch (Exception e) {
            return new ArrayList<DetalleConcepto>();
        }
    }

    public boolean actualizar(DetalleConcepto concepto) {
        try {
            local.edit(concepto);
            return true;
        } catch (Exception ex) {
            return false;
        }
    }
     public boolean guardar(DetalleConcepto concepto) {
        try {
            local.create(concepto);
            return true;
        } catch (Exception ex) {
            return false;
        }
    }

    public List<DetalleConcepto> listarDetalleConcepto() {
        try {
            return local.findAll();
        } catch (Exception e) {
            return new ArrayList<DetalleConcepto>();
        }
    }
}
